package com.lxmes.hr.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.hr.domain.NcAttendAnomalyRules;
import com.lxmes.hr.service.INcAttendAnomalyRulesService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 考勤异动规则Controller
 *
 * @author lx
 * @date 2023-04-15
 */
@Api(tags = "考勤异动规则")
@RestController
@RequestMapping("/hr/NcAttendAnomalyRules")
public class NcAttendAnomalyRulesController extends BaseController
{
	@Autowired
	private INcAttendAnomalyRulesService ncAttendAnomalyRulesService;

	/**
	 * 查询考勤异动规则列表
	 */
	@ApiOperation("查询考勤异动规则列表")
	@PreAuthorize("@ss.hasPermi('hr:NcAttendAnomalyRules:list')")
	@GetMapping("/list")
	public TableDataInfo list(NcAttendAnomalyRules ncAttendAnomalyRules)
	{
		startPage();
		List<NcAttendAnomalyRules> list = ncAttendAnomalyRulesService.selectNcAttendAnomalyRulesList(ncAttendAnomalyRules);
		return getDataTable(list);
	}

	/**
	 * 导出考勤异动规则列表
	 */
	@ApiOperation("导出考勤异动规则列表")
	@PreAuthorize("@ss.hasPermi('hr:NcAttendAnomalyRules:export')")
	@Log(title = "考勤异动规则", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, NcAttendAnomalyRules ncAttendAnomalyRules)
	{
		List<NcAttendAnomalyRules> list = ncAttendAnomalyRulesService.selectNcAttendAnomalyRulesList(ncAttendAnomalyRules);
		ExcelUtil<NcAttendAnomalyRules> util = new ExcelUtil<NcAttendAnomalyRules>(NcAttendAnomalyRules.class);
		util.exportExcel(response, list, "考勤异动规则数据");
	}

	/**
	 * 获取考勤异动规则详细信息
	 */
	@ApiOperation("获取考勤异动规则详细信息")
	@PreAuthorize("@ss.hasPermi('hr:NcAttendAnomalyRules:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id)
	{
		return AjaxResult.success(ncAttendAnomalyRulesService.selectNcAttendAnomalyRulesById(id));
	}

	/**
	 * 新增考勤异动规则
	 */
	@ApiOperation("新增考勤异动规则")
	@PreAuthorize("@ss.hasPermi('hr:NcAttendAnomalyRules:add')")
	@Log(title = "考勤异动规则", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody NcAttendAnomalyRules ncAttendAnomalyRules)
	{
		return toAjax(ncAttendAnomalyRulesService.insertNcAttendAnomalyRules(ncAttendAnomalyRules));
	}

	/**
	 * 修改考勤异动规则
	 */
	@ApiOperation("修改考勤异动规则")
	@PreAuthorize("@ss.hasPermi('hr:NcAttendAnomalyRules:edit')")
	@Log(title = "考勤异动规则", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody NcAttendAnomalyRules ncAttendAnomalyRules)
	{
		return toAjax(ncAttendAnomalyRulesService.updateNcAttendAnomalyRules(ncAttendAnomalyRules));
	}

	/**
	 * 删除考勤异动规则
	 */
	@ApiOperation("删除考勤异动规则")
	@PreAuthorize("@ss.hasPermi('hr:NcAttendAnomalyRules:remove')")
	@Log(title = "考勤异动规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids)
	{
		return toAjax(ncAttendAnomalyRulesService.deleteNcAttendAnomalyRulesByIds(ids));
	}
	/**
	 * 导入考勤异动规则
	 */
	@Log(title = "考勤异动规则", businessType = BusinessType.IMPORT)
	@PostMapping("/importData")
	public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
	{
		ExcelUtil<NcAttendAnomalyRules> util = new ExcelUtil<>(NcAttendAnomalyRules.class);
		List<NcAttendAnomalyRules> ncAttendAnomalyRulesList = util.importExcel(file.getInputStream());
		String operName = getUsername();
		String message = ncAttendAnomalyRulesService.imporIteminfo(ncAttendAnomalyRulesList, updateSupport, operName);
		return AjaxResult.success(message);
	}
	// 下载模板
	@PostMapping("/importTemplate")
	public void importTemplate(HttpServletResponse response) throws IOException
	{
		ExcelUtil<NcAttendAnomalyRules> util = new ExcelUtil<>(NcAttendAnomalyRules.class);
		util.importTemplateExcel(response,"考勤异动规则");
	}
}